/*
 * This program is free software; you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, or 
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License along 
 * with this program; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef WISHMASTER_MAINFORM_H
#define WISHMASTER_MAINFORM_H

#include <QWidget>
#include <QString>
#include <QProgressBar>
#include <QMainWindow>
#include "imagewidget.h"
#include "imageview.h"
#include "imagemanager.h"
#include "postedit.h"
#include "components/postid.h"
#include "components/post.h"
#include "misc.h"
#include "poststyle.h"

namespace Wishmaster
{
	class MainWindowController;
	class ThreadPtr;
	class Board;
}

namespace Ui
{
	struct MainWindow;
}

using namespace Wishmaster;
class PostItemView;
class SettingsFrame;
class WISHMASTER_EXPORT MainWindow : public QMainWindow
{
	Q_OBJECT
public:
	MainWindow(QWidget* parent = 0);
	virtual ~MainWindow();
	Ui::MainWindow* getUI();
	ImageViewForm* getImageView();
	ImageManager* getImageManager();
	QProgressBar* progressBar();
	bool initialize();

	QListView* threadsListView();
	QListView* hiddenListView();
	QListView* archiveListView();

	unsigned long getSelectedThread();

	void refreshThreadListView(QListView* listview);

	ThreadId getCurrentThreadId() const;

	void setChanManager(Wishmaster::ChanManager* manager);

	MainWindowController* controller() const;

public slots:
	void downloadAttachment(const PostId& postId, int index);
	PostItemView* newTab(const ThreadId& threadId);
	PostItemView* getTab(const ThreadId& threadId);
	PostItemView* currentTab() const;
	void expandThread();
	void addPost();
	void addPost(const QString& initial_text);
	void refreshTabs();
	void chanListChanged(const QStringList& chanlist);
	void hideImages(bool b);

	void zoomPostFont();
	void unzoomPostFont();

	void chanIconChanged(int index);

	void refreshThreadList();

protected:
	virtual void closeEvent(QCloseEvent* event);
	virtual bool event(QEvent* event);

	QString loadPostStyle();

protected slots:
	void updateContent(const PostId& postId, int attachmentIndex);
	void updateBoardIndex(const QString& chanName, const QString& boardName);
	void cb_board_index_changed(int index);
	void quit();
	void show_content_context_menu(const QPoint& position);
	void show_threads_context_menu(const QPoint& position);
	void watchThread(bool t);
	void hideThread();
	void createDatabase();
	void imageManager();
	void showSettings();
	void thread_activate(QModelIndex const& index);
	void archiveThreadActivate(const QModelIndex& index);
	void createThread();
	void chanChanged(int i);
	void copy();
	void copyLink();
	void boardSettings();
	void enableThreadButtons(bool e);
	void closeTab(int index);
	void tabChanged(int index);
	void imageList();
	bool editChanlist();
	void showTasklist();
	void exportThread();
	void deleteFromArchive();
	void boardListChanged(const QStringList& boardlist);
	void threadActivated(const ThreadId& threadId);
	void linkClicked(const QString& link);

private:
	void showThread(const ThreadId& threadId);
	void restoreWindowAndSplitterStates();
	void updateLeaderPic(const ThreadId& threadId);
	void updateAddressBar();

	void createController();

	Ui::MainWindow* m_ui;
	ImageViewForm* m_imageView;
	ImageManager* m_imageManager;
	SettingsFrame* m_settingsFrame;
	PostEdit* m_postedit;
	QString m_link;
	QString m_selection;
	QProgressBar* m_progressBar;
	PostStylePtr m_currentStyle;
	Chan* m_activeChan;
	int m_activeBoardIndex;
	ChanManager* m_chanmanager;
	MainWindowController* m_controller;
	ThreadId m_contextMenuThread;
};

#endif

